<?php

class Usuario extends ModelBase{
  protected static $table = "user";
  
  public static function create($data){
    unset($data['password2']);
    $data['password'] = static::hash(empty($data['password'])?'':$data['password']);
    return parent::create($data);
  }
  
  public function save(){
    if(isset($this->data['password2'])) unset($this->data['password2']);
    if(isset($this->data['password'])){
      $data_pw = $this->data['password'];
      $this->data['password'] = static::hash(empty($this->data['password'])?'':$this->data['password']);
    }
    $res = parent::save();
    if(isset($data_pw)) $this->data['password'] = $data_pw;
    return $res;
  }
  
  public static function hash($string){
    return md5(md5($string."some_salt")."some_other_salt");
  }
}